Micron Document
____ _ _ _ _
| _ \ ___ | |_ (_) _ __ ___ __| | (_) __ _
| |_) | / _ \ | __| | | | '_ \ / _ \ / _| | | | / _ |
| _ < | __/ | |_ | | | |_) | | __/ | (_| | | | | (_| |
|_| \_\ \___| \__| |_| | .__/ \___| \__,_| |_| \__,_|
|_|


The NomadNet German Wikipedia | Archives | Info
- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b

πŸ” Search

Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―Β―

Java Native Access
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
top
Java Native Access (JNA) ist eine Java-Programmbibliothek fΓΌr den Zugriff auf plattformspezifische (β€žnativeβ€œ) dynamische Programmbibliotheken (DLLs in Windows oder β€žshared librariesβ€œ auf anderen Systemen). Hierbei braucht im Unterschied zu Java Native Interface (JNI) kein plattformspezifischer Code geschrieben zu werden.

JNA ist in der Funktion mit den Platform Invocation Services (P/Invoke) des .Net-Frameworks unter Windows vergleichbar. Es unterstΓΌtzt eine automatische Umwandlung zwischen einigen C- und Java-Datentypen. Die minimal erforderliche Java-Version ist 1.4.

Contents

β€’ Lizenz
β€’ Anwendungen
β€’ Beispiel
β€’ Weblinks

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Lizenz

LGPL Version 2.1 oder hΓΆher und (ab V4.0) die Apache Software License V2.0.cite-ref-1[1]

Mapping der Datentypen

Die folgende Tabelle zeigt, wie das Mapping zwischen Java und dem nativen Code mit JNA erfolgt.cite-ref-2[2]

| Nativer Typ | Grâße | Java Typ | Standard Windows Type |
|---|---|---|---|
| char | 8-bit integer | byte | BYTE, TCHAR |
| short | 16-bit | short | short WORD |
| wchar_t | 16/32-bit character | char | WCHAR, TCHAR |
| int | 32-bit integer | int | DWORD |
| int | boolean value | boolean | BOOL |
| long | 32/64-bit integer | NativeLong | LONG |
| long long, __int64 | 64-bit integer | long | |
| float | 32-bit FP | float | |
| double | 64-bit FP | double | |
| char* | C string | String | LPCTSTR |
| void* | pointer | Pointer | LPVOID, HANDLE, LPXXX |

Anwendungen

Die folgenden Softwareprojekte verwenden JNA:

β€’ JRuby

Beispiel

Das folgende Beispiel lΓ€dt die Standard C Library, um die printf-Funktion aufzurufen. Dieses Beispiel funktioniert auf Microsoft Windows und Linux / Unix / Mac OS X.

import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Platform;
/** Einfaches Beispiel einer Deklaration und Nutzung einer Dynamischen Programmbibliothek bzw. "shared library". */
public class HelloWorld {
public interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary)Native.loadLibrary((Platform.isWindows() ? "msvcrt" : "c"),
CLibrary.class);
void printf(String format, Object... args);
}
public static void main(String[] args) {
CLibrary.INSTANCE.printf("Hello, World\n");
for (int i=0;i < args.length;i++) {
CLibrary.INSTANCE.printf("Argument %d: %s\n", i, args[i]);
}
}
}

Weblinks

β€’ Java Native Access Homepage (englisch)
β€’ Java Native Access – Download page (englisch)
β€’ Java Native Access – User Mailing List (englisch)

Einzelnachweise

cite-note-11. ↑ github.com
cite-note-22. ↑ Default Type Mappings. jna.dev.java.net, abgerufen am 2. August 2011.